package book.security;

import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;

/**
 * 用于非对称加密私钥、公钥的生成
 * @author apple
 *
 */
public class KeyPairGeneratorTest {

	public static void main(String[] args) throws NoSuchAlgorithmException {
		
		//DH/RSA/DSA
		KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
		//Keysize must be multiple of 64, and can only range from 512 to 2048 (inclusive)
		gen.initialize(512);
		KeyPair pair = gen.generateKeyPair();
		System.out.println(new BigInteger(pair.getPrivate().getEncoded()));
		System.out.println(new BigInteger(pair.getPublic().getEncoded()));
	}
}
